package org.example.iris.mapper;

import org.apache.ibatis.annotations.*;
import org.example.iris.entity.User;

@Mapper
public interface UserMapper {

    @Select("select * from user where username = #{username}")
    User findByUsername(String username);

    @Select("select * from user where email = #{email}")
    User findByEmail(String email);

    @Select("select * from user where phone = #{phone}")
    User findByPhone(String phone);

    @Select("select * from user where user_id = #{userId}")
    User findById(Integer userId);

    @Insert("insert into user(username, password, phone, role) values(#{username}, #{password}, #{phone},#{role})")
    void insertUser(User user);

    @Update("update user set username = #{username} where user_id = #{userId}")
    void update(User user);

    @Update("update user set phone = #{phoneNum} where user_id = #{userId}")
    void updatePhone(String phoneNum, Integer userId);

    @Update("update user set email = #{email} where user_id = #{userId}")
    void updateEmail(String email, Integer userId);

    @Update("update user set password = #{password} where user_id = #{userId}")
    void updatePassword(User user);

    @Delete("delete from user where user_id=#{userId}")
    void deleteUser(int userId);
}
